<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
</head>
<body>
<?php 
	include '../libs/Classes/PHPExcel/IOFactory.php';
	include 'db.php';
	$inputFileName = 'data/TU DIEN SINH VIEN.xls';
	
	//Xac dinh kieu file
	$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
	//Tao doi tuong reader de doc file
	$objReader = PHPExcel_IOFactory::createReader($inputFileType);
	//Load noi dung file
	$objPHPExcel = $objReader->load($inputFileName);
	//Doc sheet hien hanh cua file
	$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
	//hien thi
	//var_dump($sheetData);
	//echo sizeof($sheetData);
	$size = sizeof($sheetData);
	
	//import vao database
	
	$sql_query = "";
	$ms = "";
	$ht = "";
	$lop = "";
	$ns = "";
	$nu = "";
	$tt = "";
	$succeed = 0;
	$failed = 0;
		
	for ($i = 5; $i < $size; $i++){
		//echo $sheetData[$i]["B"]."<br>";
		$ms = $sheetData[$i]["B"];
		$ht = $sheetData[$i]["C"];
		$lop = $sheetData[$i]["D"];
		$ns = $sheetData[$i]["E"];
		if ($sheetData[$i]["F"] == "N"){
			$nu = 0;
		}else {
			$nu = 1;
		}
		$tt = $sheetData[$i]["G"];
		$sql_query = "Insert Into SinhVien Values('".$ms."','".$ht."','".$lop."','".$ns."','".$nu."','".$tt."')";
		$result = mysql_query($sql_query, $conn);
		if ($result){
			$succeed++;
		}else {
			$failed++;
		}
	}
	
	echo "Succeed: ". $succeed." - Failed: ". $failed;
	
	
	
	
?>
</body>
</html>